<template>
<view class="login">
  <form @submit="formSubmit" class="login-from">
    <view class="input-group">
      <view class="input-row">
        <view class="iconfont icon-shouji"></view>
        <input class="input" name="username" :value="username" placeholder="请输入手机号" @input="uninputFun">
      </view>
      <view class="input-row">
        <view class="iconfont icon-mima"></view>
        <input type="password" class="input" name="password" :value="password" placeholder="请输入密码" @input="pwdinputFun">
      </view>
    </view>
    <view class="btn-box">
      <button class="send-btn" :size="primarySize" form-type="submit" :disabled="disabled">登录</button>
    </view>
  </form>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      username: '',
      password: '',
      uninput: false,
      pwdinput: false,
      disabled: false,
      primarySize: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    this.setData({
      disabled: false
    });
    uni.removeStorageSync('userId');
    uni.removeStorageSync("userName");
    uni.removeStorageSync("userNick");
    uni.removeStorageSync("userDlass");
    uni.removeStorageSync("userGrade");
    uni.removeStorageSync("userRoleId");
    uni.removeStorageSync("userRole"); 
	uni.removeStorageSync('user');
	//wx.clearStorageSync();
    //var userId = wx.getStorageSync('userId');
    //if (userId != '') {
    //  wx.switchTab({
    //    url: '../index/index',
    //  })
    //}
  },
  onShow: function () {
    if (this.username == '' || this.password == '') {
      this.setData({
        disabled: true
      });
    } else {
      this.setData({
        disabled: false
      });
    }
  },
  methods: {
    uninputFun: function (e) {
      this.setData({
        username: e.detail.value,
        uninput: true
      });

      if (this.uninput == true && this.pwdinput == true) {
        this.setData({
          disabled: false
        });
      }
    },
    pwdinputFun: function (e) {
      this.setData({
        password: e.detail.value,
        pwdinput: true
      });

      if (this.uninput == true && this.pwdinput == true) {
        this.setData({
          disabled: false
        });
      }
    },
    formSubmit: function (e) {
      this.setData({
        disabled: true
      });
      var jsonData = {
        user_name: e.detail.value.username,
        user_pass: e.detail.value.password,
        openid: uni.getStorageSync('openId')
      };
      app.globalData.JsonPost('api/bind', jsonData, function (data) {
        //存储用户信息
        uni.setStorageSync("userId", data.data.user_id);
        uni.setStorageSync("userName", data.data.user_name);
        uni.setStorageSync("userNick", data.data.user_nick);
        uni.setStorageSync("userClass", data.data.user_class);
        uni.setStorageSync("userGrade", data.data.user_grade);
        uni.setStorageSync("userRoleId", data.data.user_role_id);
        uni.setStorageSync("userRole", data.data.user_role.role_name);
		uni.setStorageSync("fresh", 1);
        uni.switchTab({
          url: '../index/index'
        });
      });
    }
  }
};
</script>
<style>
page {
  height: 100%;
  background-color: #fff;
}

.login {
  height: 100%;
}

.login-from {
  display: block;
}

.input-group {
  padding: 30px 15px 0 15px;
}

.input-row {
  position: relative;
  margin-bottom: 18px;
}

.input-row .input {
  display: block;
  width: 100%;
  height: 40px;
  color: #000;
  font-size: 14px;
  line-height: 22px;
  padding: 8px 10px 8px 40px;
  box-sizing: border-box;
  border: 1px solid #ddd;
  border-radius: 5px;
}

.input-row .iconfont {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  font-size: 20px;
  color: #333;
  text-align: center;
  line-height: 40px;
}

</style>